package com.lr.transfer.config;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.io.File;
import java.util.regex.Pattern;

@Component
@ConfigurationProperties(prefix = TransferProperties.PREFIX)
public class TransferProperties {

    static {
        String osName = System.getProperty("os.name");
        if (Pattern.matches("Linux.*", osName)) {
            fileUploadPath = "/usr/transfer/";
        } else if (Pattern.matches("Windows.*", osName)) {
            fileUploadPath = "D:/transfer/";
        } else if (Pattern.matches("Mac.*", osName)) {
            fileUploadPath = "usr/transfer/";
        }
    }

    @PostConstruct
    public void init() {
        File file = new File(fileUploadPath);
        if (!file.exists()) {
            file.mkdirs();
        }
    }

    public static final String PREFIX = "transfer";

    private Boolean kaptchaOpen = true;


    public static String fileUploadPath;

    private Boolean haveCreatePath = false;

    private Boolean springSessionOpen = false;

    /**
     * session 失效时间（默认为30分钟 单位：秒）
     */
    private Integer sessionInvalidateTime = 30 * 60;

    /**
     * session 验证失效时间（默认为15分钟 单位：秒）
     */
    private Integer sessionValidationInterval = 15 * 60;


    public Boolean getKaptchaOpen() {
        return kaptchaOpen;
    }

    public void setKaptchaOpen(Boolean kaptchaOpen) {
        this.kaptchaOpen = kaptchaOpen;
    }


    public Boolean getSpringSessionOpen() {
        return springSessionOpen;
    }

    public void setSpringSessionOpen(Boolean springSessionOpen) {
        this.springSessionOpen = springSessionOpen;
    }

    public Integer getSessionInvalidateTime() {
        return sessionInvalidateTime;
    }

    public void setSessionInvalidateTime(Integer sessionInvalidateTime) {
        this.sessionInvalidateTime = sessionInvalidateTime;
    }

    public Integer getSessionValidationInterval() {
        return sessionValidationInterval;
    }

    public void setSessionValidationInterval(Integer sessionValidationInterval) {
        this.sessionValidationInterval = sessionValidationInterval;
    }

    public Boolean getHaveCreatePath() {
        return haveCreatePath;
    }

    public void setHaveCreatePath(Boolean haveCreatePath) {
        this.haveCreatePath = haveCreatePath;
    }
}
